package com.example.mapper;


import com.example.entity.Dish;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface DishMapper {
    //根据ID删除数据
    @Delete("delete from sky_take_out.dish where id=#{id}")
    public void delete(Integer id);

    //新增
    //返回主键
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into sky_take_out.dish(name, category_id, price, description) " +
            "VALUES (#{name},#{categoryId},#{price},#{description}) ")
    public int insert(Dish dish);

    //更新
    @Update("update sky_take_out.dish set name=#{name} where id = 74")
    public int update(Dish dish);
    //查询

    @Select("select * from sky_take_out.dish where id = #{id}")
    public Dish selectById(Integer id);

    //条件查询,引号内不能出现#{}，因此改成${}
//    @Select("select * from sky_take_out.dish where name like  '%${name}%'")
    @Select("select * from sky_take_out.dish where name like  concat('%',#{name},'%')")
    public List<Dish> list(String name);

}
